package com.ironone.mediaplayerdemo;

import android.os.Bundle;
import android.os.Handler;
import android.support.v4.app.Fragment;
import android.support.v4.widget.SlidingPaneLayout;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button;
import com.ironone.mediaplayerdemo3.R;

public class Frag1 extends Fragment {

	static Button btn1;
	Button btn2;
	View view;
	SlidingPaneLayout mPane;
	Button dragicon;

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
		// Inflate the layout for this fragment
		//fragContainer = (FrameLayout) getActivity().findViewById(R.id.fragContainer);
		
		view = inflater.inflate(R.layout.frag_one, container, false);
		mPane = (SlidingPaneLayout) getActivity().findViewById(R.id.pane);
		
		dragicon = (Button) view.findViewById(R.id.dragicon);
		btn1 = (Button) view.findViewById(R.id.menu_button1);
		btn2 = (Button) view.findViewById(R.id.menu_button2);

		dragicon.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View arg0) {
				
				dragicon.setClickable(false);
			    new Handler().postDelayed(new Runnable() {

			        @Override
			        public void run() {
			        	dragicon.setClickable(true);
			        }
			    }, 1000);
				
			    getActivity().getSupportFragmentManager().beginTransaction().add(R.id.pane2, new Frag2(), "pane2").commit();
				mPane.closePane();
			    
				// Create new fragment and transaction
				//Frag2 newFragment = new Frag2();
				//FragmentTransaction transaction = getFragmentManager().beginTransaction();
				//transaction.setCustomAnimations(R.anim.slide_right_to_middle, 0);
				// Replace whatever is in the fragment_container view with this fragment,
				// and add the transaction to the back stack
				//transaction.add(R.id.fragContainer, newFragment);
				//transaction.addToBackStack(null);

				// Commit the transaction
				//transaction.commit();
			}
		});
		
		//menu item 1 click
		btn1.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				
				// Create new fragment and transaction
				//Frag1 newFragment = new Frag1();
				//FragmentTransaction transaction = getFragmentManager().beginTransaction();
				//transaction.setCustomAnimations(0, R.anim.slide_middle_to_right);
				// Replace whatever is in the fragment_container view with this fragment,
				// and add the transaction to the back stack
				//transaction.remove(s);
				//transaction.addToBackStack(null);
				// Commit the transaction
				//transaction.commit();
				
				getActivity().getSupportFragmentManager().beginTransaction().add(R.id.pane2, new Frag3(), "pane2").commit();
				mPane.closePane();
			}
		});

		btn2.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				getActivity().getSupportFragmentManager().beginTransaction().add(R.id.pane2, new Frag4(), "pane2").commit();
				mPane.closePane();
			}
		});
		return view;
	}	
	
}
